package com.stx.chat.service.impl;

import com.stx.chat.dao.MessageDao;
import com.stx.chat.entity.Chat;
import com.stx.chat.entity.Message;
import com.stx.chat.entity.User;
import com.stx.chat.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    MessageDao messageDao;

    @Override
    public Integer sendMsg(Integer userId, String content) {

        //dao层插入对象的话能够获取对象的主键
        Message message = new Message();
        message.setContent(content);
        message.setAddtime(new Date());

        Chat chat = new Chat();
        chat.setId(1);
        message.setChat(chat);

        User user = new User();
        user.setId(userId);
        message.setUser(user);

        messageDao.sendMsg(message);

        //获取插入对象的id主键值
        return message.getId();
    }

    @Override
    public List<Message> messageList() {
        return messageDao.messageList();
    }
}
